home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 351-375 / disk_358 / scaniff / scaniff.asm < prev    next >
Assembly Source File  |  1992-05-06  |  10KB  |  254 lines

  1. ;
  2. ;   IFFscan - IFF file scanner - Jim Butterfield.  January 12/90.
  3.  
  4. ; Exec library calls
  5. _LVOOpenLibrary       EQU -$228
  6. _LVOCloseLibrary      EQU -$19E
  7. _LVOSetSignal         EQU -$132
  8. ; DOS library calls
  9. _LVOSeek              EQU -$42
  10. _LVOOutput            EQU -$3C
  11. _LVOWrite             EQU -$30
  12. _LVORead              EQU -$2A
  13. _LVOClose             EQU -$24
  14. _LVOOpen              EQU -$1E
  15. ;
  16. BufSize EQU 10
  17. ;-- Initial setup:
  18. Startup     move.l a0,a4       ; Remember ptr to argument line. cf MOVEA
  19.             move.b #0,-$1(a0,d0.W)   ; binary zero at end
  20.             lea    dosname(pc),a1    ; Name 'dos.library'.
  21.             clr.l  d0                ;   Any version (0)
  22.             move.l $4,a6             ;   Using Exec library
  23.             jsr    _LVOOpenLibrary(a6)  ;   Open Dos library.
  24.             move.l d0,a6             ; Remember DosBase ptr.
  25.             tst.l  d0                ; Check for error (d0=0 means
  26.             beq.s  StartupQuit       ;      dos not opened)
  27.             bsr.s  DOSinit
  28.             move.l a6,a1             ;-Specify Dos library in a1;
  29.             move.l $4,a6             ;   then using Exec library,
  30.             jsr    _LVOCloseLibrary(a6)    ;   close Dos library.
  31. StartupQuit rts                      ; End of Program
  32. ;
  33. ;-- Get CLI outhandle:
  34. DOSinit     jsr    _LVOOutput(a6)    ;   get CLI outhandle,
  35.             move.l d0,d7             ;   & then remember it.
  36. ;
  37. ; -- Skin leading spaces:
  38. skipspc     move.l a4,d1             ; filename start
  39.             cmp.b  #$20,(a4)+        ; space?
  40.             beq.s  skipspc
  41.             move.l #1005,d2          ; MODE_OLDFILE (for reading)
  42.             jsr    _LVOOpen(a6)
  43.             move.l d0,d6             ; file inhandle
  44.             beq.s  FileNot           ; no good, quit
  45.             link   a5,#-$1C
  46.             bsr.s  ScanFile          ; the main job
  47.             unlk   a5
  48.             move.l d6,d1             ; use the handle..
  49.             jsr    _LVOClose(a6)     ; to close the file
  50. DOSquit     rts                      ;   exit program.
  51. FileNot     move.l d7,d1             ; handle
  52.             lea    FNF.MSG(pc),a0 
  53.             move.l a0,d2     
  54.             moveq  #FNFlen,d3
  55.             jmp    _LVOWrite(a6)
  56. ;
  57. ; DOS is open and we have our in/out handles.
  58. ; Global stack definitions
  59. FileP   EQU -$4
  60. DosBase EQU -$8
  61. Type    EQU -$C
  62. Abort   EQU -$10
  63. String  EQU -$1C     ; 12 byte work area
  64. ; Look for 'FORM' or other drawer types
  65. ScanFile:   move.l a6,DosBase(a5)
  66.             moveq  #1,d4             ; start at Level 1
  67.             moveq  #0,d0
  68.             move.l d0,Abort(a5)      ; Ctrl-C trap
  69.             move.l d0,FileP(a5)      ; file position=start
  70.             bsr    ReadType
  71.             tst.l  d5                ; is it a drawer?
  72.             bne.s  GotDrawer         ; yes, exit
  73. ; First four characters are not valid type.  Give up.
  74.             move.l d7,d1             ;output handle
  75.             lea    NotIFF.MSG(pc),a0  ;message to
  76.             move.l a0,d2             ;       buffer
  77.             moveq  #NotIFFlen,d3     ;length
  78.             jsr    _LVOWrite(a6)
  79.             bra.s  SFexit
  80. ;
  81. GotDrawer   bsr.s  DoBlock           ; recursive analysis job
  82.             tst.l  Abort(a5)
  83.             beq.s  SFexit
  84.             move.l d7,d1             ;output handle
  85.             lea    CtrlCMess(pc),a0  ;message to
  86.             move.l a0,d2             ;       buffer
  87.             moveq  #3,d3             ;length
  88.             jsr    _LVOWrite(a6)
  89. SFexit      rts                       ; job complete
  90. ; D4=Recursion level      D5=Drawer Flag
  91. ; D6=Inhandle (file)      D7=Outhandle (screen)
  92. ; A4=Local Stack Frame
  93. ; A5=Global Stack Frame   A6=DosLibrary
  94. BSize       EQU     -4
  95. CSize       EQU     -8
  96. FileF       EQU     -12
  97. XType       EQU     -$10
  98. DoBlock     link    a4,#-$10          ; local variables
  99. ; read Size of this block
  100.             move.l d6,d1             ; input file handle
  101.             lea    BSize(a4),a2      ; input buff (stack) address
  102.             move.l a2,d2             ; .. to D2 for read
  103.             moveq  #4,d3             ; read 4 characters
  104.             add.l  d3,FileP(a5)      ; record file position
  105.             jsr    _LVORead(a6)      ; read 'em
  106.             move.l (a2),d0           ; take raw size
  107.             addq.l #1,d0             ; round up to even value
  108.             and.b  #$fe,d0
  109.             move.l d0,CSize(a4)      ; store rounded value
  110.             move.l FileP(a5),d1      ; start point this chunk
  111.             add.l  d1,d0             ; log end point this chunk
  112.             move.l d0,FileF(a4)
  113.             tst.w  d5                ; a drawer?
  114.             beq.s  NotDraw1
  115. ; read subType of the drawer
  116.             move.l d6,d1             ; input file handle
  117.             lea    XType(a4),a0      ; input buff (stack) address
  118.             move.l a0,d2             ; .. to D2 for read
  119.             moveq  #4,d3             ; read 4 characters
  120.             add.l  d3,FileP(a5)      ; record file position
  121.             jsr    _LVORead(a6)      ; read 'em
  122. ; print <indent> drawer Type <space> subType <newline>
  123.             bsr    ShowType
  124.             move.l d7,d1             ;output handle
  125.             lea    Spaces(PC),a0     ;message to
  126.             move.l a0,d2             ;       buffer
  127.             moveq  #1,d3             ;length=1 space
  128.             jsr    _LVOWrite(a6)
  129.             move.l d7,d1             ;output handle
  130.             lea    XType(a4),a0      ;message to
  131.             move.l a0,d2             ;       buffer
  132.             moveq  #4,d3             ;length
  133.             jsr    _LVOWrite(a6)
  134.             move.l d7,d1             ;output handle
  135.             lea    NewLine(PC),a0    ;message to
  136.             move.l a0,d2             ;       buffer
  137.             moveq  #1,d3             ;length=1 char
  138.             jsr    _LVOWrite(a6)
  139. ; Scan through size of drawer.  First, Check CTL-C
  140. NotDraw1    move.l 4,a6              ; set Exec libr
  141.             moveq  #0,d0
  142.             move.l #$1000,d1
  143.             jsr    _LVOSetSignal(a6) ;test CTRL-C
  144.             move.l DosBase(a5),a6    ;restore DOS libr
  145.             and.l  #$1000,d0
  146.             or.l   d0,Abort(a5)
  147.             tst.l  Abort(a5)
  148.             bne.s  EndSect
  149.             move.l FileP(a5),d0
  150.             cmp.l  FileF(a4),d0
  151.             bcc.s  EndSect
  152.             tst.w  d5                ; a drawer?
  153.             beq.s  NotDraw2
  154. ; Analyze drawer for sub elements - get Type!
  155.             bsr.s  ReadType
  156. ; recurse .. look inside outer drawer
  157.             addq   #1,d4
  158.             bsr    DoBlock
  159.             subq   #1,d4
  160.             moveq  #1,d5             ; restore old drawer type!
  161.             bra.s  NotDraw1
  162. ; found a non-drawer .. report it and position
  163. ; print <indent> Type <newline>
  164. NotDraw2    bsr.s  ShowType
  165.             move.l d7,d1             ;output handle
  166.             lea    NewLine(PC),a0    ;message to
  167.             move.l a0,d2             ;       buffer
  168.             moveq  #1,d3             ;length=1 char
  169.             jsr    _LVOWrite(a6)
  170. ; now position to FileP(a5)+CSize(a4)
  171.             move.l d6,d1             ;input handle
  172.             move.l FileF(a4),d2      ;new position
  173.             move.l d2,FileP(a5)      ; synchronize
  174.             moveq  #-1,d3            ;offset from start.file
  175.             jsr    _LVOSeek(a6)
  176.             bra.s  NotDraw1
  177. EndSect     unlk    a4
  178.             rts
  179. ; read Type and identify if drawer
  180. ReadType    move.l d6,d1             ; input file handle
  181.             lea    Type(a5),a2       ; input buff (stack) address
  182.             move.l a2,d2             ; .. to D2 for read
  183.             moveq  #4,d3             ; read 4 characters
  184.             add.l  d3,FileP(a5)      ; record file position
  185.             jsr    _LVORead(a6)      ; read 'em
  186. ; Look for 'FORM' or other drawer types
  187.             moveq  #1,d5             ; drawer?
  188.             moveq  #0,d0             ; zero table count
  189.             lea    Ttab,a0           ; start of table
  190.             move.l (a2),d1
  191. RTloop      cmp.l  0(a0,d0.w),d1     ; is it drawer?
  192.             beq.s  DrawerGot         ; yes, exit
  193.             addq.w #4,d0             ; try next type
  194.             cmp.w  #Ttlen,d0         ; any more?
  195.             bne.s  RTloop            ; yes, try it
  196.             moveq  #0,d5             ; not a drawer
  197. DrawerGot   rts
  198.  
  199. ; print <indent> Type..
  200. ShowType    move.l d7,d1             ;output handle
  201.             lea    Spaces(PC),a0     ;message to
  202.             move.l a0,d2             ;       buffer
  203.             move.l d4,d3             ; (Level) number of spaces
  204.             jsr    _LVOWrite(a6)
  205.             move.l d7,d1             ;output handle
  206.             lea    Type(a5),a0       ;message to
  207.             move.l a0,d2             ;       buffer
  208.             moveq  #4,d3             ;length
  209.             jsr    _LVOWrite(a6)
  210.             move.l BSize(a4),d0      ; size of block
  211. ; MakeAscii
  212.             lea    String(a5),a1     ; Address of string
  213.             moveq  #11,d2            ; size of string
  214. DigLoop     swap   d0                ; hi/lo swap
  215.             moveq  #0,d1
  216.             move.w d0,d1
  217.             beq.s  Skipper
  218.             divu   #10,d1
  219. Skipper     move.w d1,d0
  220.             swap   d0
  221.             move.w d0,d1
  222.             divu   #10,d1
  223.             move.w d1,d0
  224.             swap   d1
  225.             or.b   #$30,d1
  226.             move.b d1,0(a1,d2.w)
  227.             tst.l  d0
  228.             dbeq   d2,DigLoop
  229.             lea    0(a1,d2.w),a0
  230.             move.b #$20,-(a0)
  231.             move.l d7,d1             ; outhandle
  232.             moveq  #13,d3            ; max string size
  233.             sub.b  d2,d3             ; less unused
  234.             move.l a0,d2             ; num string address
  235. ; d2 string position, d3 length
  236.             jsr _LVOWrite(a6)
  237.             rts
  238.  
  239. Ttab        dc.b 'FORM'
  240.             dc.b 'CAT '
  241.             dc.b 'LIST'
  242.             dc.b 'PROP'
  243. Ttlen       EQU  *-Ttab
  244. FNF.MSG     dc.b 'File not found.',$a
  245. FNFlen      EQU  *-FNF.MSG
  246. NotIFF.MSG  dc.b 'Not an IFF file!',$a
  247. NotIFFlen   EQU  *-NotIFF.MSG
  248. Spaces      dc.b '                        '
  249. dosname     dc.b 'dos.library',0
  250. CtrlCMess   dc.b '^C'
  251. NewLine     dc.b $0a
  252.             end
  253.